<?php

App::uses('GenericUtil', 'Lib');

class ImportshcronShell extends AppShell {

	public $uses = array('Feed');

    function main() {
    	$ds = null;
    	try {
			CakeLog::info("Inizio import soccerhistory", "importcron");
			$feeds = $this->Feed->find("all",array("recursive"=>-1,"limit"=>800, "fields"=>array("Feed.id"),"conditions"=>array("Feed.type"=> FEED_TYPE_SOCCERHISTORY, "Feed.state"=>FEED_STATE_NO_IMPORT,"Feed.country_code is not null")));
		    // $ds = $this->Email->getDataSource();
			// $ds->begin();
			foreach ($feeds as $feed) {
		    	try {
					CakeLog::info("Import soccerhistory feed " . $feed["Feed"]["id"], "importcron");
					GenericUtil::soccerfixtures($feed["Feed"]["id"], $this);
					// $ds->commit();
		    	} catch (Exception $e) {
		    		CakeLog::error($e->getMessage(),"importcron");
		    	}
			}
			CakeLog::info("Fine import soccerhistory", "importcron");
    	} catch (Exception $e) {
    		CakeLog::error($e->getMessage(),"importcron");
	    	// if (isset($ds)) {
	    		// $ds->rollback();
				// CakeLog::error("Rollback", "importcron");
			CakeLog::info("Fine import soccerhistory con errori", "importcron");
    	}
	}
}


?>